import Vue from 'vue'
import VueRouter from 'vue-router'


import {dyroutes} from "@/router/index";

Vue.use(VueRouter)
//原始路由数组，添加路由时应在此处添加。
export var origindyroutes = [
    {
        path: '/',
        name: '主页',
        component: () => import('../views/DEVLayout.vue'),
    },

    {
        path: '/cyj',
        name: '抽油机',
        component: () => import('../views/DEVLayout.vue'),
        redirect: '/cyj/tj',
        children: [
            {path: 'tj', name: '抽油机停机', component: () => import('../views/CyjTJ.vue')},
            {path: 'tj2', name: '抽油机停机2', component: () => import('../views/CyjTJ2.vue')},
        ]
    },
    {
        path: '/jcxx',
        name: '基础信息维护',
        component: () => import('../views/DEVLayout.vue'),
        children: [
            {path: 'djxxwh', name: '单井信息维护', component: () => import('../views/DJXXWH.vue')},
            {path: 'dwxxwh', name: '单位信息维护', component: () => import('../views/DWXXWH.vue')},
            {path: 'gxxxwh', name: '干线信息维护', component: () => import('../views/GXXXWH.vue')},


        ]
    },
    {
        path: '/acount',
        name: '账号管理',
        component: () => import('../views/DEVLayout.vue'),
        // redirect: '/role',

        children: [
            // {path: 'city', name: '城市', component: () => import('@/views/City.vue')},
            {path: 'welcome', name: '欢迎主页', component: () => import('@/views/Welcome.vue')},
            {path: 'yjssQx', name: '油井实时曲线', component: () => import('../views/YjssQx.vue')},
            {path: 'file', name: '文件管理', component: () => import('../views/File.vue')},
            {path: 'user', name: '用户管理', component: () => import('../views/User.vue')},
            {path: 'role', name: '角色管理', component: () => import('../views/Role.vue')},
            {path: 'menu', name: '菜单管理', component: () => import('../views/Menu.vue')},

        ]
    },
    // {
    //     path: '/pcs',
    //     name: 'pcs',
    //     component: () => import('../views/DEVLayout.vue'),
    //     children: [
    //         {path: 'zb', name: '指标下载', component: () => import('../views/ZhiBiao.vue')},
    //         {path: 'qx', name: '回水曲线', component: () => import('../views/HsQx.vue')},
    //     ]
    // },
]

//通过递归深拷贝恢复路由数组数据
function copyArr(orgroutearr, dstroutearr) {
    for (var i = 0; i < orgroutearr.length; i++) {
        var obj = {
            name: orgroutearr[i].name,
            path: orgroutearr[i].path,
            component: orgroutearr[i].component,
            children: []
        }
        dstroutearr.push(obj);
        // console.log(dstroutearr)
        if (orgroutearr[i].children != null && orgroutearr[i].children.length > 0) {
            dstroutearr.forEach(item => {
                if (item.name == orgroutearr[i].name) {
                    copyArr(orgroutearr[i].children, item.children)
                }
            })
        }
    }
}

//通过深拷贝原始数据恢复dyroutes，origindyroutes=>dyroutes
export function restoredyroutes1() {

    copyArr(origindyroutes, dyroutes)

    // console.log('dydydydydydy')
    // console.log(dyroutes)
}

// export default router